import Vue from 'vue';
import Router from 'vue-router';
import Route from '@/components/Route.vue';
import NotFoundComponent from '@/components/NotFoundComponent.vue';
import Top from '@/components/Top.vue';
import Bottom from '@/components/Bottom.vue';
import Main from '@/components/Main';
import Test from '@/components/Test';
import Login from '@/components/Login.vue';
import HomeNews from '@/components/news/Home-news.vue';
import SinaNews from '@/components/news/Sina-news.vue';
import IfengNews from '@/components/news/Ifeng-news.vue';
import SohuNews from '@/components/news/Sohu-news.vue';


Vue.use(Router);

var router_news = {
  path: "/news"
}



const _router = new Router({
  // mode: 'history',
  routes: [
    {
      path: '/',
      component: Route,
      redirect: '/main',
      children: [
        {
          path: 'main',
          redirect: '/main/home-news ',
          components: {
            top: Top,
            main: Main,
            bottom: Bottom
          },

          children: [
            {
              path: 'home-news',
              component: HomeNews

            },
            {
              path: 'sina-news',
              component: SinaNews
            },
            {
              path: 'ifeng-news',
              component: IfengNews
            },
            {
              path: 'sohu-news',
              component: SohuNews

            }

          ]

        }
      ]
    },
    {
      path: '/test',
      name: 'test',
      component: Test
    },
    {
      path: '/login',
      name: 'login',
      component: Login
    }
  ]
});
_router.beforeEach((to, from, next) => {
  //登入验证
  if (to.path != '/login') {
    if (!sessionStorage.getItem('user')) {
      next({ path: '/login' })
    } else {
      next();
    }
  } else {
    next();
  }

})
export default _router
